package org.fund.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.fund.base_service.domain.OptionalFund;
import org.fund.base_service.domain.vo.OptionalFundVO;
import org.fund.base_service.service.OptionalFundService;
import org.fund.common.core.domain.BaseResult;
import org.fund.common.model.FundValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自选基金(OptionalFund)表控制层
 *
 * @author makejava
 * @since 2022-03-13 01:28:43
 */
@RestController
@RequestMapping("/optionalFund")
@Api(tags = "自选基金")
public class OptionalFundController {
    /**
     * 服务对象
     */
    @Autowired
    private OptionalFundService optionalFundService;

    /**
     *
     *
     * @return 查询结果
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public BaseResult<OptionalFundVO> queryAll() {
        return BaseResult.success(this.optionalFundService.queryAll());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping
    @ApiOperation(value = "通过主键查询单条数据")
    public BaseResult<OptionalFundVO> queryById(@RequestParam("id") Integer id) {
        return BaseResult.success(this.optionalFundService.queryById(id));
    }

    /**
     *
     * @param optionalFund 实体
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增关注")
    public BaseResult<OptionalFund> add(@RequestBody OptionalFund optionalFund) {
        return BaseResult.success(this.optionalFundService.insert(optionalFund));
    }

    /**
     * 编辑数据
     *
     * @param optionalFund 实体
     * @return 编辑结果
     */
    @PutMapping
    @ApiOperation(value = "编辑数据")
    public BaseResult<OptionalFund> edit(@RequestBody OptionalFund optionalFund) {
        return BaseResult.success(this.optionalFundService.update(optionalFund));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "删除")
    @DeleteMapping
    public BaseResult<Boolean> deleteById(Integer id) {
        return BaseResult.success(this.optionalFundService.deleteById(id));
    }
    @ApiOperation(value = "获取历史净值")
    @GetMapping("/lsjz")
    public BaseResult<FundValue> historyJZ(@ApiParam(value="基金代码") @RequestParam("fundCode")String fundCode,
                                           @ApiParam(value="条数") @RequestParam("pageSize")int pageSize,
                                           @ApiParam(value="结束日期") @RequestParam("endDate")String  endDate) {
        return BaseResult.success(optionalFundService.getHistoryJZ(fundCode,pageSize,endDate));
    }
}

